package com.yyy.dm.consumer.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyy.dm.CommonResponse;
import com.yyy.dm.VoUtil;
import com.yyy.dm.dao.SchedulerMapper;
import com.yyy.dm.scheduler.DmScheduler;
import com.yyy.dm.scheduler.TimePlanDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class SchedulerConsumerService {

    @Resource
    private SchedulerMapper schedulerMapper;

    public CommonResponse getTimePlan(Long itemId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("itemId",itemId);
        List<DmScheduler> schedulerList = schedulerMapper.selectList(queryWrapper);
        List<TimePlanDTO> timePlanDTOList = new ArrayList<>();
        for (DmScheduler dmScheduler : schedulerList) {
            TimePlanDTO timePlanDTO = new TimePlanDTO();
            BeanUtils.copyProperties(dmScheduler,timePlanDTO);
            timePlanDTOList.add(timePlanDTO);
        }
        return VoUtil.returnSuccess(timePlanDTOList);
    }
}
